﻿@model  HANS_BackStage.Model.DbModel.Backstage_admin
@{
    ViewBag.Title = "修改管理员";
    var RoleList = ViewData["AllRoles"] as List<HANS_BackStage.Model.DbModel.Backstage_role>;
    var RoleListSelf = ViewData["MyRole"] as List<HANS_BackStage.Model.DbModel.Backstage_role>;
}
<div class="x_panel">
    <!--beginHead-->
    <div class="x_title">
        <h2>修改管理员 <small>HANS</small></h2>
        <ul class="nav navbar-right panel_toolbox">
            <li>
                <a class="collapse-link"><i class="fa fa-chevron-up"></i></a>
            </li>
        </ul>
        <div class="clearfix"></div>
    </div>
    <!--endHead-->
    <div class="x_content">
        <!--beginForm-->
        @using (Html.BeginForm("UpdateAdmin", "Account", FormMethod.Post,
                                            new { @class = "form-horizontal form-label-left js-form-submit", @novalidate = "" }))
        {
            @Html.AntiForgeryToken()
            <div class="form-group">
                <label class="control-label col-md-3 col-sm-3 col-xs-12" for="first-name">
                    账号<span class="required">*</span>
                </label>
                <div class="col-md-6 col-sm-6 col-xs-12">
                    @Html.TextBoxFor(i => i.Name, new { @class = "form-control col-md-7 col-xs-12",@readOnly="readonly" })
                </div>
            </div>
            <div class="form-group">
                <label class="control-label col-md-3 col-sm-3 col-xs-12" for="first-name">
                    昵称<span class="required">*</span>
                </label>
                <div class="col-md-6 col-sm-6 col-xs-12">
                    @Html.TextBoxFor(i => i.Nickname, new { @class = "form-control col-md-7 col-xs-12" })     
                </div>
                @Html.ValidationMessageFor(i => i.Nickname, null, new { @class = "text-danger" })
              
            </div>
            <div class="form-group">
                <label class="control-label col-md-3 col-sm-3 col-xs-12" for="first-name">
                    真实姓名<span class="required">*</span>
                </label>
                <div class="col-md-6 col-sm-6 col-xs-12">
                    @Html.TextBoxFor(i => i.Truename, new { @class = "form-control col-md-7 col-xs-12", @placeholder = "中文" })
                </div>
                @Html.ValidationMessageFor(i => i.Truename, null, new { @class = "text-danger" })
            </div>
            <div class="form-group">
                <label class="control-label col-md-3 col-sm-3 col-xs-12" for="first-name">
                    性别<span class="required">*</span>
                </label>
                <div class="col-md-6 col-sm-6 col-xs-12">
                    @Html.HiddenFor(i => i.Sex)<!--"js-select-sex"[针对性别，必须有个隐藏，从JS赋值]-->
                    <select class="form-control js-select-sex" id="sex">
                        <option value="1">男</option>
                        <option value="2">女</option>
                        <option value="0">不详</option>
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label class="control-label col-md-3 col-sm-3 col-xs-12" for="first-name">
                    年龄<span class="required">*</span>
                </label>
                <div class="col-md-6 col-sm-6 col-xs-12">
                    @Html.TextBoxFor(i => i.Age, new { @class = "form-control col-md-7 col-xs-12", @type = "number", @min = "0", @max = "100" })
                </div>
            </div>
            <div class="form-group">
                <label class="control-label col-md-3 col-sm-3 col-xs-12">
                    角色<span class="required">*</span>
                </label>
                <div class="col-md-6 col-sm-6 col-xs-12">
                    @Html.Hidden("Roles")<!--保存多选的select的值-->
                    <select id="roleSelect" class="form-control js-select2-select js-select-role" multiple="multiple">
                        @{
                            foreach (var role in RoleList)
                            {
                                string roleSelectStr = "";
                                if (RoleListSelf.Any(r => r.Rolename == role.Rolename))
                                {
                                    roleSelectStr = "selected=\"selected\"";
                                }
                                <option value="@role.Id" @roleSelectStr>@role.Rolename</option>

                            }
                        }
                    </select>  
                </div>
            </div>
            <div class="ln_solid"></div><!--条横线-->
            <div class="form-group">
                <div class="col-md-6 col-sm-6 col-xs-12 col-md-offset-3">
                    <button type="submit" class="btn btn-success">保存</button>
                    <a href="@HttpContext.Current.Request.UrlReferrer" class="btn btn-default">取消</a>
                </div>
            </div>
        }
        <!--endForm-->
    </div>
</div>
@section Scripts{
    <script type="text/javascript">
        $(function () {
            //$('#Roles').val($('.js-select-role').val());
            changeSelect('#sex',@Model.Sex);
            changeValue('#Roles','.js-select-role');
        })
         var changeStringRole = { selectClass: ".js-select-role", selectValString: "#Roles" };
        $('.js-select-role').change(changeStringRole, SetChangeSelectString);//角色更改赋值

        var changeStringSex = { selectClass: ".js-select-sex", selectValString: "#Sex" };
        $('.js-select-sex').change(changeStringSex, SetChangeSelectString);//性别更改赋值
    </script>
}